/*
 * ${beanName}ServiceImpl.java created on ${config.createTime?string("yyyy-MM-dd")} by ${config.createUser}
 */
package ${config.pack}.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import ${config.pack}.entity.${beanName};
import ${config.pack}.entity.${beanShowVo};
import ${config.pack}.entity.${beanQueryVo};
import ${config.pack}.service.${beanName}Service;
import org.eking.framework.common.BusinessMap;
import org.eking.framework.common.Constants;
import org.eking.framework.common.Pager;
import org.eking.framework.dao.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * ${config.beanDescription} Service 实现
 * TODO javadoc for ${config.pack}.service.impl.${beanName}ServiceImpl
 * @Copyright: ${config.copyright}
 * @author: ${config.createUser}
 * @since: ${config.createTime?string("yyyy-MM-dd HH:mm:ss")}
 */
@Service("${beanName?uncap_first}Service")
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ${beanName}ServiceImpl implements ${beanName}Service {

	/**
	 * MyBatis 命名空间
	 */
	private final static String MAPPER_NAMESPACE = "${config.pack}.mappers.${beanName}Mapper";

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	
	@Transactional
	@Override
	public BusinessMap create(${beanName} ${simpleBeanName}) throws Exception {
		BusinessMap bm = new BusinessMap();
		sqlSessionTemplate.insert(MAPPER_NAMESPACE + ".add", ${simpleBeanName});
		return bm;
	}

	@Override
	public boolean isExists(${beanName} ${simpleBeanName}) throws Exception {
		return (Integer)sqlSessionTemplate.selectOne(MAPPER_NAMESPACE + ".isExists", ${simpleBeanName}) > 0;
	}
	
	@Override
	public ${beanName} getById(String ${beanId}) throws Exception {
		return sqlSessionTemplate.selectOne(MAPPER_NAMESPACE + ".getById", ${beanId});
	}
	
	@Transactional
	@Override
	public BusinessMap edit(${beanName} ${simpleBeanName}) throws Exception {
		BusinessMap bm = new BusinessMap();
		sqlSessionTemplate.update(MAPPER_NAMESPACE + ".edit", ${simpleBeanName});
		return bm;
	}

	@Transactional
	@Override
	public boolean delete(String ${beanId}) throws Exception {
		sqlSessionTemplate.delete(MAPPER_NAMESPACE + ".deleteById", ${beanId});
		return true;
	}

	@Override
	public Pager<${beanShowVo}> search(Pager<${beanShowVo}> pager,${beanQueryVo} ${simpleBeanName}QueryVo) throws Exception {
		List dataList = sqlSessionTemplate.selectList(MAPPER_NAMESPACE + ".page", ${simpleBeanName}QueryVo, new RowBounds((pager.getCurrentPage() - 1) * pager.getLimit(), pager.getLimit()));
		pager.setDataList(dataList);
		Long total = sqlSessionTemplate.selectOne(MAPPER_NAMESPACE + ".getTotal", ${simpleBeanName}QueryVo);
		pager.setTotal(total);
		return pager;
	}

}
